package app.view.component 
{
	import app.facade.App;
	import app.view.component.movie.Schwanker;
	import com.temple.core.CoreMovieClip;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author hungconcon
	 */

	[Embed(source="../../../../lib/ui.swf", symbol="HumanRun")]
	public class HumanRun extends CoreMovieClip {
	
		public var schwanker:Schwanker;
		public var rootX:Number;
		
		public var fallLeft:MovieClip;
		public var fallRight:MovieClip;
		
		public function HumanRun() {
			addEventListener(Event.ADDED_TO_STAGE, onInital);
		}
		
		public function onInital(evt:Event):void {
			this.gotoAndStop(1);
			fallLeft.visible = false;
			fallRight.visible = false;
			schwanker.visible = false;
			schwanker.stop();
			stage.addEventListener( Event.RESIZE, onResize );
			this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
			fallLeft.addFrameScript(fallLeft.totalFrames - 1, fallLeftEnd);
			fallRight.addFrameScript(fallRight.totalFrames - 1, fallRightEnd);	
			onResize(evt);
		}
		
		public function fallLeftEnd():void{
			fallLeft.stop();
		}
		
		public function fallRightEnd():void{
			fallRight.stop();
		}
		
		
		public function downRight():void {
			fallRight.visible = true;
			schwanker.visible = false;
			fallRight.gotoAndPlay(1);
			
			sendNotification(App.FINISH_GAME);
		}
		
		public function downLeft():void 
		{
			fallLeft.visible = true;
			schwanker.visible = false;
			fallLeft.gotoAndPlay(1);
			
			sendNotification(App.FINISH_GAME);
		}
		
		public function onEnterFrame(evt:Event):void {
			this.x = int(rootX) +  App.rotationSchwanker;
		}
		public function onResize(evt:Event):void {
			this.x = 500//App.deviceSize.width / 2 - this.width / 2;
			this.y = 570//App.deviceSize.height / 2;// - schwanker.height - 200;
			
			rootX = this.x;
		}
		
		public function startGame():void {
			schwanker.visible 	= true;
			fallLeft.visible 	= false;
			fallRight.visible 	= false;
			schwanker.run();
		}
	}
}